﻿using System.Collections.Generic;
using TestBat.IModels.Domain;
using TestBat.IModels.Models;
using TestBat.IViewModels.Workspaces.Gradings;
using TestBat.ServiceLocator;
using TestBat.ViewModels.Base;

namespace TestBat.ViewModels.Workspaces.Gradings
{
    public class TraineeComboBoxViewModel : ComboBoxViewModel<ITraineeComboBoxItemViewModel, ITrainee>, ITraineeComboBoxViewModel
    {
        public TraineeComboBoxViewModel(IScheduleModel scheduleModel)
        {
            this.scheduleModel = scheduleModel;
        }

        public event SelectedScheduleEventHandler SelectedSchedule;

        protected override ITraineeComboBoxItemViewModel RecreateDefault()
        {
            return DefaultServiceLocator.Get<ITraineeComboBoxItemViewModel>();
        }

        protected override IList<ITraineeComboBoxItemViewModel> RecreateItems()
        {
            var list = new List<ITraineeComboBoxItemViewModel>();

            ISchedule schedule = null;
            if (SelectedSchedule != null)
                schedule = SelectedSchedule();

            if (schedule != null)
            {
                IList<ITrainee> trainees = scheduleModel.GetTrainees(schedule);

                foreach (var t in trainees)
                {
                    var vm = DefaultServiceLocator.Get<ITraineeComboBoxItemViewModel>(); // TODO: use DI
                    vm.Item = t;
                    list.Add(vm);
                }
            }

            return list;
        }

        private readonly IScheduleModel scheduleModel;
    }
}
